﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenTK.Mathematics;

namespace Test.UI.OpenGL.Animations;

/// <summary>
/// 模态测量点
/// </summary>
/// <param name="ampX">X方向幅值</param>
/// <param name="ampY">Y方向幅值</param>
/// <param name="ampZ">Z方向幅值</param>
/// <param name="phaseX">X方向相位（弧度）</param>
/// <param name="phaseY">Y方向相位（弧度）</param>
/// <param name="phaseZ">Z方向相位（弧度）</param>
/// <param name="vertexIndex">测量点索引（对应3D模型中的顶点索引）</param>
public struct ModalPoint(float ampX, float ampY, float ampZ, float phaseX, float phaseY, float phaseZ, int vertexIndex)
{
    /// <summary>
    /// X方向幅值
    /// </summary>
    public float AmplitudeX { get; set; } = ampX;

    /// <summary>
    /// Y方向幅值
    /// </summary>
    public float AmplitudeY { get; set; } = ampY;

    /// <summary>
    /// Z方向幅值
    /// </summary>
    public float AmplitudeZ { get; set; } = ampZ;

    /// <summary>
    /// X方向相位（弧度）
    /// </summary>
    public float PhaseX { get; set; } = phaseX;

    /// <summary>
    /// Y方向相位（弧度）
    /// </summary>
    public float PhaseY { get; set; } = phaseY;

    /// <summary>
    /// Z方向相位（弧度）
    /// </summary>
    public float PhaseZ { get; set; } = phaseZ;

    /// <summary>
    /// 测量点索引（对应3D模型中的顶点索引）
    /// </summary>
    public int VertexIndex { get; set; } = vertexIndex;

    /// <summary>
    /// 根据时间计算当前位移
    /// </summary>
    /// <param name="time">时间（秒）</param>
    /// <param name="frequency">频率（Hz）</param>
    /// <param name="amplificationFactor">放大系数</param>
    /// <returns>位移向量</returns>
    public readonly Vector3 CalculateDisplacement(float time, float frequency, float amplificationFactor = 1.0f)
    {
        float omega = 2.0f * MathF.PI * frequency;

        float dispX = AmplitudeX * MathF.Cos(omega * time + PhaseX) * amplificationFactor;
        float dispY = AmplitudeY * MathF.Cos(omega * time + PhaseY) * amplificationFactor;
        float dispZ = AmplitudeZ * MathF.Cos(omega * time + PhaseZ) * amplificationFactor;

        return new Vector3(dispX, dispY, dispZ);
    }

    /// <summary>
    /// 根据时间和频率获取位移（不带放大系数）
    /// </summary>
    /// <param name="time">时间（秒）</param>
    /// <param name="frequency">频率（Hz）</param>
    /// <returns>位移向量</returns>
    public readonly Vector3 GetDisplacement(float time, float frequency)
    {
        return CalculateDisplacement(time, frequency, 1.0f);
    }
}